package com.sgcc.ln.pmos.e_ln_home.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.utils.DateUtils;
import com.sgcc.ln.pmos.e_ln_home.bean.InfomationListBean;

public class InfomationListAdapter extends BaseQuickAdapter<InfomationListBean.DataBean.ListBean, BaseViewHolder> {

    private Context mContext;

    public InfomationListAdapter(Context context) {
        super(R.layout.item_infomation);
        mContext = context;
    }

    public interface OnItemClickListener {
        //条目点击
        void itemClickListener(int position, InfomationListBean.DataBean.ListBean bean);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, InfomationListBean.DataBean.ListBean bean) {
        baseViewHolder.setText(R.id.tv_name, TextUtils.isEmpty(bean.getTitle()) ? "" : bean.getTitle());
        String time = "";
        try {
            time = StringUtils.isEmpty(DateUtils.getStrng_to_Times_ymdhms(bean.getOperateDate())) ?
                    DateUtils.get_TimesYMDHMSG(bean.getOperateDate()) :
                    DateUtils.getStrng_to_Times_ymdhms(bean.getOperateDate());
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        baseViewHolder.setText(R.id.tv_time, "更新时间：" + time);

        baseViewHolder.getView(R.id.ll_body).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.itemClickListener(getItemPosition(bean), bean);
                }
            }
        });
    }



}


